package com.xquant.databasemanagement.bean.table;

import org.apache.commons.lang.StringUtils;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.xquant.databasemanagement.bean.DataBaseObject;

import java.util.ArrayList;
import java.util.List;


@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class TableBean extends DataBaseObject {

    @JacksonXmlProperty(isAttribute = true)
    private String tableSpaces;

    @JacksonXmlProperty(isAttribute = true)
    private String tableAnnotation;

    @JacksonXmlProperty(localName = "column")
    @JacksonXmlElementWrapper(localName = "columnList")
    private List<ColumnBean> tableColumns;

    @JacksonXmlProperty(localName = "primaryKey")
    @JacksonXmlElementWrapper(localName = "primaryKeyList")
    private List<PrimaryKeyBean> tablePrimaryKeys;

    @JacksonXmlProperty(localName = "index")
    @JacksonXmlElementWrapper(localName = "indexList")
    private List<IndexesBean> tableIndexes;

    public List<IndexesBean> groupIndexes;
    public List<IndexesBean> groupUniqueIndexes;
    public List<PrimaryKeyBean> primaryKeys;
    public List<PrimaryKeyBean> uniqueKeys;

    public TableBean(){
        tableColumns = new ArrayList<>();
        tablePrimaryKeys = new ArrayList<>();
        tableIndexes = new ArrayList<>();
    }

    public String getTableSpaces() {
        return tableSpaces;
    }

    public void setTableSpaces(String tableSpaces) {
        this.tableSpaces = tableSpaces;
    }

    public String getTableAnnotation() {
        return tableAnnotation;
    }

    public void setTableAnnotation(String tableAnnotation) {
        this.tableAnnotation = tableAnnotation;
    }

    public List<ColumnBean> getTableColumns() {
        return tableColumns;
    }

    public void setTableColumns(List<ColumnBean> tableColumns) {
        this.tableColumns = tableColumns;
    }

    public List<PrimaryKeyBean> getTablePrimaryKeys() {
        return tablePrimaryKeys;
    }

    public void setTablePrimaryKeys(List<PrimaryKeyBean> tablePrimaryKeys) {
        this.tablePrimaryKeys = tablePrimaryKeys;
    }

    public List<IndexesBean> getTableIndexes() {
        return tableIndexes;
    }

    public void setTableIndexes(List<IndexesBean> tableIndexes) {
        this.tableIndexes = tableIndexes;
    }

    public List<IndexesBean> getGroupIndexes() {
        return groupIndexes;
    }

    public void setGroupIndexes(List<IndexesBean> groupIndexes) {
        this.groupIndexes = groupIndexes;
    }

    public List<IndexesBean> getGroupUniqueIndexes() {
        return groupUniqueIndexes;
    }

    public void setGroupUniqueIndexes(List<IndexesBean> groupUniqueIndexes) {
        this.groupUniqueIndexes = groupUniqueIndexes;
    }

    public List<PrimaryKeyBean> getPrimaryKeys() {
        return primaryKeys;
    }

    public void setPrimaryKeys(List<PrimaryKeyBean> primaryKeys) {
        this.primaryKeys = primaryKeys;
    }

    public List<PrimaryKeyBean> getUniqueKeys() {
        return uniqueKeys;
    }

    public void setUniqueKeys(List<PrimaryKeyBean> uniqueKeys) {
        this.uniqueKeys = uniqueKeys;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (obj instanceof TableBean){
            TableBean tableBean = (TableBean) obj;
            return StringUtils.equals(tableBean.getName(),this.getName()) &&
                    StringUtils.equals(tableBean.getTableAnnotation(),this.getTableAnnotation()) &&
                    StringUtils.equals(tableBean.getTableSpaces(),this.getTableSpaces()) &&
                    tableBean.getTableColumns().equals(this.getTableColumns()) &&
                    tableBean.getTableIndexes().equals(this.getTableIndexes()) &&
                    tableBean.getTablePrimaryKeys().equals(this.getTablePrimaryKeys());
        }
        return false;
    }
}
